#!/bin/sh

######################################
#       Slackware Build Script       #
######################################
#  BUILDS: Desklaunch                #
#    HOME: http://www.oroborus.org   #
#  AUTHOR: Lehman Black              #
# CONTACT: bzqwerty[at]gmail[dot]com #
######################################

# Modified by the SlackBuilds.org project

PRGNAM=desklaunch
VERSION=1.1.5
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=`pwd`
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i486" ]; then
	SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i586" ]; then
	SLKCFLAGS="-O2 -march=i586 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
	SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

rm -rf $PKG $PRGNAM-$VERSION
mkdir -p $TMP $PKG/usr/bin $OUTPUT
cd $TMP
tar xvf $CWD/${PRGNAM}_$VERSION.tar.gz || exit 1
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R a-s,u+w,go+r-w .

# Modify the Makefile so it will use custom CFLAGS if needed
sed -i 's%CFLAGS    =%CFLAGS    +=%g' Makefile

CFLAGS="$SLKCFLAGS" make || exit 1

# Rather than use the install target in the Makefile, let's just install the
# binary manually into the package directory - this avoids having to remove
# directories that are unnecessarily created by the install target
install -D -m 0755 desklaunch $PKG/usr/bin/desklaunch

strip --strip-unneeded $PKG/usr/bin/desklaunch

# Install the example desklaunchrc file provided by Debian :)
cat debian/example_rc > $PKG/usr/doc/$PRGNAM-$VERSION/desklaunchrc.example

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a README LICENSE $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/usr/man/man1
cat debian/desklaunch.1 | gzip -9 > $PKG/usr/man/man1/desklaunch.1.gz

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
